﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using MSPToolkit.Encodings;

namespace MSPToolkitSampleApp.UtilitesSamples
{
    public partial class EncodingsSample : PhoneApplicationPage
    {
        public EncodingsSample()
        {
            InitializeComponent();
        }

        private void OnEncodeDecode_Click(object sender, RoutedEventArgs e)
        {
            var encoding = BaseSingleByteEncoding.GetEncoding(1251);    //also you can write "var encoding = new Windows1251Encoding();"
            byte[] bytes = encoding.GetBytes(tbSourceText.Text);
            string decoded = encoding.GetString(bytes, 0, bytes.Length);

            tbEncoded.Text = string.Join(", ", bytes.Select(t => string.Format("0x{0:X2}", t)));
            tbDecoded.Text = decoded;
        }
    }
}